#include<bits/stdc++.h>
using namespace std;
int t, n, a[200005], sum[200005], b[200005], ans;
void dfs(int x){
    if(x > n){
        int xa = 0, xb = 0, sumx = 0;
        for (int i = 1; i <= n; i ++){
            if(b[i] == 1){
                sumx += (a[i] == a[xa]) * a[i];
                xa = i;
            }
            if(b[i] == 2){
                sumx += (a[i] == a[xb]) * a[i];
                xb = i;
            }
        }
        ans = max(ans, sumx);
        return ;
    }
    b[x] = 1;
    dfs(x + 1);
    b[x] = 2;
    dfs(x + 1);
    return ;
}
int main(){
    ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> t;
    while(t --){
        cin >> n;
        ans = 0;
        memset(a, 0, sizeof(a));
        memset(sum, 0, sizeof(sum));
        memset(b, 0, sizeof(b));
        for (int i = 1; i <= n; i ++){
            cin >> a[i];
            sum[a[i]] ++;
        }
        b[1] = 1;
        dfs(1);
        cout << ans << endl;
    }
    return 0;
}
